<!-- 回答 -->
<template>
	<view>
		<view class="box mh32 " v-for="(item, index) in question">
			<view class="sunshine">
				<view v-if="item.comment_count==0?true:false" @click="clickEntrance(item.id)">
					<view class="wenben text32 " style="display: flex;">
						<i class="iconfont icon-wenda1-copy color105 text44" style="margin-right:24rpx;"></i>
						<text class="text36">{{ item.content }}</text>
					</view>

					<view class="wenben text32 mt28" style="display: flex;">
						<view class="substance sunshine">
							<view class="record	 text24 mt30 ">
								<view style="display: flex;align-items : center;center;margin-left: 64rpx;">
									<u-avatar :src="item.avatar" :size="50"></u-avatar>
									<text class="color3B" style="margin-left: 8rpx;">{{item.comment_list?item.comment_list.username:'' }}</text>
									<view style="margin-left: 8rpx;">提出一个问题</view>
								</view>
								<view>{{ item.comment_count }}回答</view>
							</view>
						</view>
					</view>
				</view>
				<view v-else @click="clickEntrance(item.id)">
					<view class="wenben text32 " style="display: flex;">
						<i class="iconfont icon-wenda1-copy color105 text44" style="margin-right:24rpx;"></i>
						<text class="text36">{{ item.content }}</text>
					</view>

					<view class="wenben text32 mt28" style="display: flex;" v-if="item.comment_list?(item.comment_list.content != '' ? true : false):''">
						<i class="iconfont icon-wenda-copy colorBO6 text44" style="margin-right:24rpx;"></i>
						<view class="substance sunshine">
							<text class=" normalColor text28">{{ item.comment_list.content }}</text>
							<view class="record	 text24 mt30 ">
								<view style="display: flex;align-items : center;">
									<u-avatar :src="item.comment_list.avatar" :size="50"></u-avatar>
									<text class="color3B" style="margin-left: 8rpx;">{{ item.comment_list.username }}</text>
									<view style="margin-left: 8rpx;">回答了一个问题</view>
								</view>
								<view>{{ item.comment_count }}回答</view>
							</view>
						</view>
					</view>
					<view class="answer record text24 " v-else>
						<view style="display: flex;align-items : center;margin-left: 64rpx;">
							<u-avatar :src="src" :size="50"></u-avatar>
							<text class="color3B" style="margin-left: 8rpx;">{{item.comment_list?item.comment_list.username:''}}</text>
							<view style="margin-left: 8rpx;">回答了一个问题</view>
						</view>
						<view>{{ item.comment_count }}回答</view>
					</view>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
import { questionsList } from '@/api/home.js'
export default {
	name: 'answer',
	data() {
		return {
			question: [],
			page: 1,
			hasdata: false,
			src: '',
			userId: 0
		};
	},
	created(){
		this.getQuestionList(this.page);
	},
	methods: {
		// 下拉刷新：
		dropDown() {
			console.log('问答下拉');
			this.question = [];
			this.page = 1;
			this.hasdata = false;
			this.getQuestionList(this.page);
		},
		// 上拉加载：
		raise() {
			console.log('问答上拉');
			if (!this.hasdata) {
				return;
			}
			this.page++;
			this.getQuestionList(this.page);
		},
		//问答列表
		getQuestionList(page) {
			let self = this;
			questionsList({ page: page, user_id: self.userId }).then(res => {
				if (self.page == 1) {
					self.question = [];
					self.question = res.data.list;
				} else {
					self.question = self.question.concat(res.data.list); //实际返回数据的字段
				}
				console.log(111, self.question);
				self.hasdata = self.page < res.data.pagination.page_count;
				uni.stopPullDownRefresh();
			})
			.catch(err => {
				console.log(err);
			});
		},
		clickEntrance(id) {
			uni.navigateTo({
				url: `../../pages/index/answer-details?id=${id}`
			});
		}
	}
};
</script>

<style lang="scss">
.sunshine {
	width: 100%;
}
.answer {
	margin-top: 50rpx;
	width: 100%;
}
.box {
	display: flex;
	justify-content: space-between;
	margin-top: 48rpx;
	padding-bottom: 28rpx;
	border-bottom: 1rpx solid #efefef;
}
.wenben {
}
.record {
	display: flex;
	justify-content: space-between;
	align-items: center;
	color: #abaaaa;
}
</style>
